package scaladuct.hint

import scaladuct._

/**
 * <p>
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: Sep 1, 2010
 * Time: 9:27:59 PM
 */

class HintsPrompt[X](val hasHints: HasHints[X], val level: Int, val subject: String, defaultResult: X, pageId: String) extends HintPage[X] {
  val id = pageId
  type HintType = hasHints.HintType

  val getCookie: ListCookie[Property[hasHints.HintType]] = new ListCookie[Property[hasHints.HintType]] {
    var value = hasHints.hints(null)
  }

  def consume(cookie: Cookie): ConfigResult[X] = {
    // The cookie should contain either an empty list or a list with a single hint. In the first case, the empty list
    // means the user selected no hint. The single hint in the second case represents the selected hint.
    if (cookie.value == Nil) {
      NewStarter(new BasicStarter[X](defaultResult))
      //throw new IllegalStateException("todo") // todo
    } else {
      NextPage(hasHints.hintPage(cookie.value.head))
    }
  }

}

object HintsPrompt {
  def apply[X](hasHints: HasHints[X], level: Int, subject: String, defaultResult: X, pageId: String): HintsPrompt[X] = {
    new HintsPrompt(hasHints, level, subject, defaultResult, pageId)
  }
}

//class HintsPromptCookie(@Size(min = 0, max = 1) var hints: List[Annotation])

trait HintPage[X] extends ConfigPage[X] {
  type HintType
  final type Cookie = ListCookie[Property[HintType]]
}
